package jssia.database.mysql.columns;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public abstract class StringColumn extends Column {

    public String get(ResultSet rs) throws SQLException {
        return rs.getString(fullyQualifiedName);
    }

    public abstract long getMaxLength();

    public void set(PreparedStatement ps, int index, String val) throws SQLException {
        if (val.length() > getMaxLength())
            throw new IllegalArgumentException("String length of " + val.length() + " is too long for column " + fullyQualifiedName
                    + ". The maximum length in characters is " + getMaxLength() + ".  The string giving you problems has a value of "
                    + val);

        ps.setString(index, val);
    }
}
